import router from './router'
import { ElLoading } from 'element-plus'
// import { useLoginStore } from './store/login';
import jsCookie from "js-cookie"
const witheList = ['/login']
// const Login = useLoginStore()
let fullscreenLoading
router.beforeEach((to, from, next) => {
    fullscreenLoading = ElLoading.service({
        lock: true,
        text: 'Loading',
        background: 'rgba(0, 0, 0, 0.7)',
    })
    let token = jsCookie.get('token')
    if (token) {
        if (to.path === '/login') {
            next('/')
        } else {
            next()
        }
    }else{
        if (witheList.includes(to.path)) {
            next()
        } else {
            next("/login")
        }
    }

});

router.afterEach((to, from) => {
    fullscreenLoading.close()

});